package com.data2wisdom.comm.base.mybatis;


import java.util.Properties;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import tk.mybatis.spring.mapper.MapperScannerConfigurer;
/**
 * MyBatis扫描配置
 * @author LV
 *
 */
@Configuration
//必须在MyBatisConfig注册后再加载MapperScannerConfigurer，否则会报错
@AutoConfigureAfter(MyBatisConfig.class)
public class MyBatisMapperScannerConfig implements EnvironmentAware{
	@Autowired
    private Environment env;
    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
//        mapperScannerConfigurer.setBasePackage("com.data2wisdom.dcp.biz.mapper");
//        mapperScannerConfigurer.setBasePackage("com.data2wisdom.es.mapper");
//        mapperScannerConfigurer.setBasePackage("com.data2wisdom.nodemgr.dao");
        mapperScannerConfigurer.setBasePackage(env.getProperty("mybatis.mapper.basepackage"));
        Properties properties = new Properties();

        properties.setProperty("mappers", "com.data2wisdom.comm.base.mybatis.MyMapper");
        properties.setProperty("notEmpty", "false");

        properties.setProperty("mappers", MyMapper.class.getName());
        mapperScannerConfigurer.setProperties(properties);

        return mapperScannerConfigurer;
    }
	@Override
	public void setEnvironment(Environment environment) {
		this.env=environment;
		
	}
}
